package com.holystone.splunk.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

/**
 * Copyright (c) 2015, HOLYSTONE Technologies, Inc. All right reserved.
 *
 * @desc:
 * @author:王凯征
 * @date:2015年11月3日 下午4:32:56
 */
public class Md5Utils {

    public static String EncoderByMd5(String str) throws Exception {
        String newstr = null;
        // 确定计算方法
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            // 加密后的字符串
            newstr = base64en.encode(md5.digest(str.getBytes("utf-8")));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return newstr;
    }
}
